package com.vivachek.protocol.converts


/**
 * @Author: YCB
 * @Time: 2022/9/26 18:41
 * @Email: congbin.yuan@vivachek.com
 * @Description: 解析设备序列号
 */
private const val COMMAND = 119
private const val EXPAND_CODE = 170
private const val LENGTH = 16
internal class SNConvert : DataConvert(COMMAND, EXPAND_CODE, LENGTH) {

    override fun parse(data: List<Int>,origin:List<Int>) {
        val sn = StringBuilder()
        data.forEach {
            if (it<48) return@forEach
            if (it.toChar().toString().isNotBlank()){
                sn.append(it.toChar())
            }
        }
        var ret = sn.toString()
        if (ret.length >= 13) {
            ret = ret.substring(2,ret.length)
        }
        listener?.sn(ret)
    }
}